<template>
  <div class="projects">
    <h1>项目展示</h1>
    <ul>
      <li v-for="project in projects" :key="project.id" @click="handleClick(project.img)">
        <span class="project-img">
          <img :src="project.img" alt="项目图片">
        </span>
        <span class="project-name">{{ project.name }}</span>
      </li>
    </ul>
    <div :class="ClassNames('modelPlat', {show: Boolean(modelPath)})">
      <h1>模型展示</h1>
      <ModelPlatView :modelPath="modelPath"/>
    </div>
  </div>
</template>

<script setup>
import { reactive, ref } from 'vue';
import ModelPlatView from '@/components/ModelPlatView.vue';
import ClassNames from 'classnames';
let modelPath = ref('');
const projects = reactive([
  {
    id: 1,
    img: '123',
    name: '项目1'
  },
  {
    id: 2,
    img: '234',
    name: '项目2'
  }
]);
function handleClick(img) {
  modelPath.value=img
}
</script>

<style scoped lang="scss">
.projects{
  position: relative;
}
  ul {
    list-style: none;
    padding: 0;
    display: flex;
    align-items: center;
    width: 1200px;
    margin: 0 auto;
    li {
      margin-bottom: 10px;
      width: 250px;
      height: 250px;
      border: 1px solid #000;
      padding: 5px;
      margin-right: 20px;
      display: flex;
      flex-direction: column;
      justify-content: space-between;
      cursor: pointer;
      .project-img{
        width: 100%;
        height: 200px;
        background: #ccc;
        img {
          width: 100%;
          height: 100%;
        }
      }
      .project-name{
        width: 100%;
        text-align: center;
        font-size: 18px;
        font-weight: bold;
        line-height: 50px;
        height: 50px;
        overflow: hidden;
        white-space: nowrap;
        text-overflow: ellipsis
      }
    }
  }
  h1 {
    text-align: center;
  }
  .modelPlat{
    position: absolute;
    left: 100%;
    width: 0;
    height: 100%;
    top: 0;
    opacity: 0;
    transition: all 0.5s;
    background: #fff;
  }
  .show{
    width: 100%;
    height: 100%;
    opacity: 1;
    left: 0;
  }
</style>